package presentation;

import java.awt.*;

import javax.swing.BorderFactory;
import javax.swing.UIManager;
import javax.swing.border.Border;

public class Liveview {
	private static final long serialVersionUID = 1L;

	static void renderSplashFrame(Graphics2D g, int frame, int percent) {
        final String[] comps = {"Loading data from OD...", 
        		"Generating graphical user interface...", 
        		"Starting data and webcam streaming...",
        		"Done"};
        g.setComposite(AlphaComposite.Clear);
        g.fillRect(0,155,350,61);
        g.setPaintMode();
        g.setColor(Color.white);
        g.setFont(new Font("Arial",Font.PLAIN,12));
      	g.drawString("Version 1.0", 10, 170);
        g.drawString(comps[frame]+"...", 10, 190);
        g.fillRect(10, 197, 330, 15);
        g.setColor(new Color(0,70,132));
        Double width = percent * 326./100.;
        g.fillRect(12, 199, width.intValue(), 11);
    }
    
    public static void main (String args[]) {
    	try {
			UIManager.getDefaults().put("TabbedPane.contentAreaColor",Color.white);
			UIManager.getDefaults().put("TabbedPane.highlight",Color.red);
			UIManager.getDefaults().put("TabbedPane.selected",Color.white);
			UIManager.put("ToolTip.background", Color.white);
			Border border = BorderFactory.createLineBorder(Color.gray);
			UIManager.put("ToolTip.border", border);
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
		} catch (Exception e) {
			// Not handled.
		}
		
		PMain pMain;
        final SplashScreen splash = SplashScreen.getSplashScreen();
        if (splash != null) {
        	Graphics2D g = splash.createGraphics();
        	if (g != null) {
        		renderSplashFrame(g, 0, 0);
        		splash.update();

        		pMain = new PMain();
        		renderSplashFrame(g, 1, 30);
        		splash.update();

        		pMain.createUserInterface();
        		renderSplashFrame(g, 2, 90);
        		splash.update();

        		pMain.startStreaming();
        		renderSplashFrame(g, 3, 100);
        		splash.update();
        	} else {
        		pMain = new PMain();
            	pMain.createUserInterface();
            	pMain.startStreaming();
        	}
        } else {
        	pMain = new PMain();
        	pMain.createUserInterface();
        	pMain.startStreaming();
        }
        
        if (splash != null) {
        	splash.close();
        }
        
        pMain.showGUI();
    }
}